/**
 * @description 自定义路由拦截
 */
 


export default async function() {
	const list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
	// 用遍历的方式分别为,uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器
	list.forEach(item => {
		uni.addInterceptor(item, {
			invoke(e) {
				const url = e.url.split('?')[0]// 获取要跳转的页面路径（url去掉"?"和"?"后的参数）
				
				var whiteList = [
					'/pagesA/admin/login',
					'/pages/index/index3',
					'/pages/index/index',
					'/pages/index/index2',
					'/pagesA/admin/profile',
					'/pagesA/admin/commission',
					"/pagesC/product/product/newindex",
					"/pagesC/store/joinlist",
					"/pagesC/store/joininfo",
					"/pages/business/business/index",
					"/pages/business/business/add",
					"/pages/business/business/edit",

					// "/pagesC/product/brank/type/product/index",
					// "/pagesC/product/brank/type/product/edit",
					// "/pagesC/product/brank/type/product/add",

					// "/pagesC/product/goodstype/index",
					// "/pagesC/product/goodstype/edit",
					// "/pagesC/product/goodstype/add",


			

					// "/pagesC/product/brank/type/index",
					// "/pagesC/product/brank/type/add",
					// "/pagesC/product/brank/type/edit",

					// "/pagesC/product/brank/index",
					// "/pagesC/product/brank/add",
					// "/pagesC/product/brank/edit",

					"/pagesB/shop/index",
					"/pagesB/shop/bags/index",
					

					"/pagesB/shop/bags/product/index",// 箱包列表
					"/pagesB/shop/bags/product/add",// 箱包列表
					"/pagesB/shop/bags/product/edit",// 箱包列表

					"/pagesB/merchant/pwdlogin",//商户登录
					"/pagesB/merchant/index",//商户主页
					"/pagesB/merchant/checkcode",//获取验证码

					"/pagesB/merchant/songjian",
					"/pagesB/merchant/addorder",
					"/pagesB/merchant/daiqian",
					"/pagesB/merchant/face",
					"/pagesB/merchant/face1",
					"/pagesB/merchant/order",
					"/pagesB/merchant/payed",
					"/pagesB/merchant/ruku",
					"/pagesB/merchant/songjian",
					"/pagesB/merchant/waitingpay",
					"/pagesB/merchant/ydz",
					"/pagesB/merchant/yicheck",
					"/pagesB/merchant/yiqian",


					"/pagesB/seller/checkinfo",
					"/pagesB/seller/checkwl",
					"/pagesB/seller/songjian",
					"/pagesB/seller/face",
					"/pagesB/seller/face1",

					"/pagesB/merchant/info",
					"/pagesD/shenpi/index",
					"/pagesD/shenpi/add",
					"/pagesD/shenpi/edit",
				]	
				
			
				
				if(uni.getStorageSync("qxrouter").length>0)
				{
					uni.getStorageSync("qxrouter").forEach((item,index)=>{
						whiteList.push(item)

					})
				}
				let pass = false
			

				if (whiteList) {// 判断当前窗口是白名单，如果是则不重定向路由
					pass = whiteList.some((item) => {
						if (typeof(item) === 'object' && item.pattern) {
							return item.pattern.test(url)
						}
					
						 return url === item
					})
				}
				// let userInfo = uni.getStorageSync('auth')
				// console.log('url路由拦截-用户缓存', pass, userInfo, !userInfo)
				// 不是白名单并且没有token
				if (!pass) {
					uni.showToast({
						title: '您未权限',
						icon: 'none'
					})
					
					return false
				}
				return e
			},
			fail(err) { // 失败回调拦截
				console.log(err)
			}
		})
	})
}